﻿// Page8.cpp: 实现文件
//

#include "pch.h"
#include "Wgdll.h"
#include "Page8.h"
#include <iostream>


// Page8 对话框

IMPLEMENT_DYNAMIC(Page8, CDialog)

Page8::Page8(CWnd* pParent /*=nullptr*/)
	: CDialog(IDD_PAGE8, pParent)
{

}

Page8::~Page8()
{
}

void Page8::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(Page8, CDialog)
	ON_BN_CLICKED(IDC_BUTTON1, &Page8::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &Page8::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &Page8::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_CHECK1, &Page8::OnBnClickedCheck1)
END_MESSAGE_MAP()


// Page8 消息处理程序
CCheat g_cheat;

void Page8::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	//SetDlgItemText(IDC_EDIT1, __T("1111111111"));
	g_cheat.Initialize();
	//std::cout << "作弊";
}


void Page8::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	g_cheat.Release();
}


void Page8::OnBnClickedButton3()
{
	// TODO: 在此添加控件通知处理程序代码
	::MessageBox(NULL, __T("11111"), __T(""), MB_OK);

}

int (WINAPI* Real_MessageBox)(
	HWND hWnd,
	LPCTSTR lpText,
	LPCTSTR lpCaption,
	UINT uType
	) = MessageBox;

int WINAPI My_MessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
{
	lpText = __T("helloworld");
	return Real_MessageBox(hWnd, lpText, lpCaption, uType);
}

void Page8::OnBnClickedCheck1()
{
	// TODO: 在此添加控件通知处理程序代码
	if (((CButton*)GetDlgItem(IDC_CHECK1))->GetCheck())
	{
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());
		DetourAttach(&(PVOID&)Real_MessageBox, My_MessageBox);
		DetourTransactionCommit();

	}
	else
	{
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());
		DetourDetach(&(PVOID&)Real_MessageBox, My_MessageBox);
		DetourTransactionCommit();
	}
}
